<?php
include "./inc/header.php";

title('php常用方法测试');

clogList(
	array(
		'preg_replace()',

		'gettype()',
		'isset()',
		'var_dump()',

		'bin2hex()',

		'mb_convert_encoding()',
		'mb_detect_encoding()',

		'fputcsv()',
		'fopen()',
		'fclose()',
		'fwrite()',
		'fread()',
	)
);

comment('获取数据类型');
$nums = array(1, 2, 3, 4, 5);
clog(gettype($nums));
var_dump($nums);

comment('正则表达式');
clog(preg_replace('#[^0-9a-z]#', '', 'hello_@sow'));

comment('判断是否赋值');
clog(isset($dog->bigName) ? 'yes' : 'no');


comment('csv相关方法');
$fp = fopen('demo.csv', 'w');
fputcsv($fp, array('name', 'role', 'age'));
fputcsv($fp, array('one' => 'lufy', 'two' => 'captain', 'three' => 11)); // 只获取values,添加新行

comment('转换为hex');
$str = '未来光年';
$str = 'LOOK';
clog($str);
clog('转换前 bin2hex:' . bin2hex($str));

comment('多字节字符编码转换');
$encStr = mb_convert_encoding($str, 'utf-16le', 'utf-8');
clog('encoding convert result:' . $encStr);
clog('转换后 bin2hex:' . bin2hex($encStr));

comment('字符编码自动检测');
echo mb_detect_encoding($encStr, 'auto');

comment('查看变量');
var_dump($encStr);

include 'inc/footer.php';